<!--
* coder  : dzlua
* email  : 505544956@qq.com
* module : ApiMgr-client
* path   : src/views
* file   : home.vue
* time   : 2017-11-17 11:14:03
-->
<template>
  <div class="home">
    <am-header></am-header>
    <el-tag type="success">{{ username }}</el-tag>
    <el-button type="text" @click="logout">登出</el-button>
    <am-footer></am-footer>
  </div>
</template>

<script>
  export default {
    name: 'home',
    data () {
      return {
        username: JSON.parse(window.localStorage.getItem('user')).username
      }
    },
    methods: {
      logout () {
        let user = JSON.parse(window.localStorage.getItem('user'))
        this.$api.req({
          url: 'logout',
          method: 'POST',
          token: user.access_token
        }, resp => {
          if (!resp.status.success) {
            this.$message.error(resp.status.message)
            return
          }
          window.localStorage.setItem('user', null)
          this.$message.success(resp.status.message)
          this.$router.push({ name: 'login' })
        })
      }
    }
  }
</script>
